using HotChocolate.Language;

namespace HotChocolate.Types;

/// <summary>
/// The PositiveInt scalar type represents a signed 32‐bit numeric non‐fractional
/// value of at least the value 1.
/// </summary>
public class PositiveIntType : IntType
{
    /// <summary>
    /// Initializes a new instance of the <see cref="PositiveIntType"/> class.
    /// </summary>
    public PositiveIntType(
        string name,
        string? description = null,
        BindingBehavior bind = BindingBehavior.Explicit)
        : base(name, description, min: 1, bind: bind)
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="PositiveIntType"/> class.
    /// </summary>
    [ActivatorUtilitiesConstructor]
    public PositiveIntType()
        : this(
            WellKnownScalarTypes.PositiveInt,
            ScalarResources.PositiveIntType_Description)
    {
    }

    /// <inheritdoc />
    protected override bool IsInstanceOfType(IntValueNode valueSyntax)
    {
        return IsInstanceOfType(base.ParseLiteral(valueSyntax));
    }

    /// <inheritdoc />
    protected override SerializationException CreateParseLiteralError(IValueNode valueSyntax)
    {
        throw ThrowHelper.PositiveIntType_ParseLiteral_ZeroOrLess(this);
    }

    /// <inheritdoc />
    protected override SerializationException CreateParseValueError(object runtimeValue)
    {
        throw ThrowHelper.PositiveIntType_ParseValue_ZeroOrLess(this);
    }
}
